/*
 * @Descripttion: 
 * @Author: voanit
 * @Date: 2022-09-04 08:45:20
 * @LastEditors: voanit
 * @LastEditTime: 2022-09-04 15:46:21
 */
export { }


/* 类型注解 */
let num: number = 1
/* 联合类型 */
let num2: number | string | boolean = 1
/* 类型别名 */
type Tnum = {
  n: number
}
let num3: Tnum = {
  n: 4
}

/* 对象类型 */
type Tobj = {
  id: number,
  name: string
}

/* 接口 */
interface Tobj3 {
  id: number
  name: string
}
var obj: Tobj = {
  id: 1,
  name: 'rose'
}
var obj2: {
  id: number,
  name: string,
  f1?: () => void,
  f2?(): void
} = {
  id: 1,
  name: 'rose'
}


var obj3 = {
  id: 1,
  name: 'rose'
}

/* typeof */
type Tobj2 = typeof obj3

var obj4: Tobj3 = {
  id: 1,
  name: 'rose'
}
/* 类型断言 */
var obj5 = {} as Tobj2
var obj6 = {} as typeof obj3

/* 函数类型 */
function f3(a: number, b: number): number {
  return a + b
}


type Tfn = (a: number, b: number) => number
const f4: Tfn = (a, b) => {
  return a + b
}

/* 继承 */
interface Tobj4 {
  id: number,
  name: string
}
interface Tobj5 extends Tobj4 {
  age: number
}

var obj10: Tobj5 = {
  id: 1,
  name: 'qq',
  age: 1
}

/* 泛型 */
function f5<T, S, Q>(a: T, b: S, c?: Q): T {
  return a
}

// f5(1, 2)
// f5('name', 'age')
f5(1, '2')


function ff(fn) {
  /* 1-原始写法 */
  // if (fn) {
  //   fn()
  // }

  /* 2-简写 */
  // fn && fn()
  /* 3-可选链写法 */
  fn?.()
}

ff(() => { })
const obj123 = {
  second: '1'
}
let nestedProp = obj123!.second;